package com.tour.tour.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tour.tour.common.Response;
import com.tour.tour.entity.HotelEntity;
import com.tour.tour.service.HotelService;
import com.tour.tour.service.impl.HotelServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 76004
 * @apiNote
 * @date 2023/5/13 17:52
 */
@RestController
@RequestMapping("/hotel")
@CrossOrigin
public class HotelController{
    @Autowired
    private HotelService hotelService;

    @PostMapping("/add")
    public Response<Void> add(@RequestBody HotelEntity hotelEntity){
        hotelService.save(hotelEntity);
        return Response.success();
    }

    @DeleteMapping("/delete")
    public Response<Void>delete(Long id){
        hotelService.removeById(id);
        return Response.success();
    }
    @PutMapping("/update")
    public Response<Void>update(@RequestBody HotelEntity hotelEntity){
        hotelService.updateById(hotelEntity);
        return Response.success();
    }

    @GetMapping("/getPage")
    public Response<List<HotelEntity>>getPage(Integer pageNum, Integer pageSize){;
        return Response.success(hotelService.page(new Page<HotelEntity>(pageNum,pageSize), new QueryWrapper<HotelEntity>()).getRecords());
    }

    @GetMapping("/getById")
    public Response<HotelEntity>getById(Long id){
        return Response.success(hotelService.getById(id));
    }






}
